package com.lanou.controller;


import com.fasterxml.jackson.databind.util.JSONPObject;
import com.lanou.bean.Users;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.Map;

@Controller
@RequestMapping("index")
public class IndexController {


    RestTemplate restTemplate = new RestTemplate();

    /**
     * @Author shw
     * @Description
     * @Param
     * @Date    根据用户名查询权限等信息
     */
    @RequestMapping("/home.do")
    @ResponseBody
    public ModelAndView toLogin(@RequestParam Map<String, Object> map) throws UnsupportedEncodingException {
        ModelAndView modelAndView=new ModelAndView("base/home");
        MultiValueMap multiValueMap = new LinkedMultiValueMap();
        multiValueMap.setAll(map);
        //乱码转码
        String username= (String) map.get("username");
        username=new String(username.getBytes("iso-8859-1"),"utf-8");
        //调用接口,根据用户名查询用户权限
        String result = restTemplate.postForObject("http://10.90.87.240:9090/menu/getMenuListByUserName",multiValueMap,String.class);
        modelAndView.addObject("result",result);
        modelAndView.addObject("loginUser",username);
        return modelAndView;

    }


}